/*
 * @ : Copyright (c) 2021 Phytium Information Technology, Inc. 
 *  
 * SPDX-License-Identifier: Apache-2.0.
 * 
 * @Date: 2021-08-25 10:27:00
 * @LastEditTime: 2021-08-26 18:23:43
 * @Description:  This files is for i2c ctrl function definition
 * 
 * @Modify History: 
 *  Ver   Who         Date         Changes
 * ----- ------      --------    --------------------------------------
 * 1.0   Wangxiaodong 2021/8/26   init
 */
#ifndef BSP_DRIVERS_FT_WDT_H
#define BSP_DRIVERS_FT_WDT_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "ft_types.h"
#include "ft_debug.h"
#include "ft_error_code.h"
#include "kernel.h"


typedef struct
{
    u32 instance_id;/* wdt id */
    u32 refresh_baseAddr;/* wdt更新寄存器基地址 */
    u32 control_baseAddr;/* wdt控制寄存器基地址 */
    u32 irq_num;/* wdt中断号 */
    u32 irq_prority;/* wdt中断优先级 */
    const char *instance_name;/* instance name */
}FWdtConfig;/* wdt配置 */

typedef struct
{
    FWdtConfig config;/* wdt配置 */
    u32 is_ready;/* wdt初始化完成标志 */
}FWdtCtrl;

#define FWDT_SUCCESS          FT_SUCCESS  
#define FWDT_ERR_INVAL_PARM   FT_MAKE_ERRCODE(ErrModBsp, ErrBspWdt, BIT(1))
#define FWDT_ERR_NOT_READY    FT_MAKE_ERRCODE(ErrModBsp, ErrBspWdt, BIT(2))
#define FWDT_ERR_TIMEOUT      FT_MAKE_ERRCODE(ErrModBsp, ErrBspWdt, BIT(3))
#define FWDT_ERR_NOT_SUPPORT  FT_MAKE_ERRCODE(ErrModBsp, ErrBspWdt, BIT(4))
#define FWDT_ERR_CMD_FAILED   FT_MAKE_ERRCODE(ErrModBsp, ErrBspWdt, BIT(5))
#define FWDT_ERR_DMA_READ_FAILED  FT_MAKE_ERRCODE(ErrModBsp, ErrBspWdt, BIT(6))

#define FWDT_DEBUG_TAG "WDT"
#define FWDT_ERROR(format, ...)   FT_DEBUG_PRINT_E(FWDT_DEBUG_TAG, format, ##__VA_ARGS__)
#define FWDT_INFO(format, ...) FT_DEBUG_PRINT_I(FWDT_DEBUG_TAG, format, ##__VA_ARGS__)
#define FWDT_DEBUG(format, ...) FT_DEBUG_PRINT_D(FWDT_DEBUG_TAG, format, ##__VA_ARGS__)

const FWdtConfig *FWdtLookupConfig(u32 instanceId);
u32 FWdtSetTimeout(FWdtCtrl *pCtrl, u32 timeout);
u32 FWdtGetTimeleft(FWdtCtrl *pCtrl);
u32 FWdtRefresh(FWdtCtrl *pCtrl);
u32 FWdtStart(FWdtCtrl *pCtrl);
u32 FWdtStop(FWdtCtrl *pCtrl);

u32 FWdtReadWCVH(FWdtCtrl *pctrl);
u32 FWdtReadWCVL(FWdtCtrl *pctrl);
u32 FWdtReadWOR(FWdtCtrl *pctrl);
u32 FWdtReadWCS(FWdtCtrl *pctrl);

#ifdef __cplusplus
}
#endif

#endif